package com.kalua.list.dbaccess.user;

import org.springframework.cassandra.core.RowMapper;

import com.datastax.driver.core.Row;
import com.datastax.driver.core.exceptions.DriverException;
import com.kalua.list.dbaccess.DAOConstants;
import com.kalua.list.domainmodel.UUIDIdentifier;
import com.kalua.list.domainmodel.security.UserCredentials;
import com.kalua.list.domainmodel.security.UserCredentialsImpl;

public class UserCredentialsRowMapper 
					implements RowMapper<UserCredentials>, DAOConstants {
	
	public static final String USER_CREDENTIALS_COL_FAMILY_NAME = "user_credentials";
	public static final String PASSWORD_COL_NAME = "password";
	public static final String SALT_COL_NAME = "salt";

	@Override
	public UserCredentials mapRow(Row row, int rowNumber) throws DriverException 
	{ return UserCredentialsRowMapper.mapToEntity(row, rowNumber); }

	public static UserCredentials mapToEntity(Row row, int rowNumber) {
		UserCredentials result;		
		UUIDIdentifier id = 
				new UUIDIdentifier(row.getUUID(ACCOUNT_REF_COLUMN_NAME));
		String password = row.getString(PASSWORD_COL_NAME);
		String salt = row.getString(SALT_COL_NAME);
		result = new UserCredentialsImpl(id, password, salt);
		return result;
	}
}